package leetcode.code2044;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

public class Solution implements IDebug {

	int max;
	int ans;
	int len;

	public int countMaxOrSubsets(int[] nums) {
		max = 0;
		ans = 0;
		len = nums.length;
		this.countMaxOrSubsets(nums, 0, 0);
		return ans;
	}

	private void countMaxOrSubsets(int[] nums, int index, int sum) {
		if (index == len) {
			if (sum == max) {
				ans += 1;
			} else if (sum > max) {
				max = sum;
				ans = 1;
			}
			return;
		}
		this.countMaxOrSubsets(nums, index + 1, sum);
		this.countMaxOrSubsets(nums, index + 1, sum | nums[index]);
	}

	@Override
	public void debug1() {
		HelpDebug.compare(6, this.countMaxOrSubsets(HelpDebug.str2array3("[3,2,1,5]")));

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
